<script language="javascript">
   $(document).ready(function() {
    $('#blogtable').dataTable( {
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
      "bStateSave": true,
     "aaSorting": [[ 0, "desc" ]]
    } );
} );

</script>
<div>
    <div><a href="/blog/index/">List</a></td><td><a href="/blog/add/">New</a></td></tr></div>
          <table id="blogtable" align="center" width="100%" cellspacing="2" cellpadding="2" bordercolor="#e0e0e0" border="0" style="border:solid 1px #e0e0e0; border-radius:5px;margin-left: 20px;border-right-width: 1px;width: 1323px;margin-top: 20px;margin-bottom: 20px; ">
              <thead>
                  <tr>
     
                  <td>Title</td>
                  <td>&nbsp;</td>
                  <td>Status</td>
                  <td>Category</td>
                  <td>Access</td>
                  <td>Created BY</td>
                  <td>Date</td>
                  <td>Hits</td>
                  <td>ID</td>
                  </tr>

              </thead>
              
              <tbody>

              <?php foreach($this->blogarr as $blogarr):

                       if($blogarr['state'] == 1)
			{
				$status = "<img src='/images/admin/publish.png' title='unpublish' />";
			} else {
				$status = "<img src='/images/admin/publish_x.png' title='publish' />";
			}



                      ?>
            <tr>
   
                  <td><a href="/blog/edit/id/<?php echo $blogarr["id"] ?>"><?php echo $blogarr["title"] ?></a><br>Alias : <?php echo $blogarr["alias"] ?></td>
                    <td><a href="javascript: void(0);" onclick="deleteNews('<?php echo $blogarr['id']; ?>')"><img src="/images/admin/icons/delete.gif" width="18" height="18" /></a></td>
                  <td><a href="javascript: void(0);" onclick="changeBlogStatus('<?php echo $blogarr['id']; ?>')"><?php echo $status; ?></a></td>
                    <td><?php echo $blogarr["state"] ?></td>
                  <td><?php echo $blogarr["catid"] ?></td>
                  <td><?php echo $blogarr["access"] ?></td>
                  <td><?php echo $blogarr["created_by"] ?></td>
                  <td><?php echo $blogarr["publish_up"] ?></td>
                  <td><?php echo $blogarr["hits"] ?></td>
                  <td><?php echo $blogarr["id"] ?></td>
             </tr>
      
           <?php endforeach;?>
          </tbody>
          </table>

      </div>
<script language="javascript">

        function deleteNews(id)
        {
            if(confirm("Are you sure that you want to delete this post?"))
                {
                     location.href="/blog/delete/id/"+id;
                }
                else{
                    return false;
                }


        }

        function changeBlogStatus(id)
{
	$("#loader").show();
	$("#loader").html("<img src='/images/loader.gif' /> loading...");

	$.ajax({
        type: "POST",
        data: ({id: id}),
        url: "/blog/changestatus/",
        success: function(data){
            $("#loader").hide();
            window.location.reload();
        }
    });
}

 </script>